package com.tudouji.project.pay.controller;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.interceptor.annotation.RepeatSubmit;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.pay.domain.SfPrebalanceRecord;
import com.tudouji.project.pay.service.ISfPrebalanceRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 销售订单回款核销记录Controller
 *
 * @author tudouji
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/pay/prebalance")
public class SfPrebalanceRecordController extends BaseController
{
    @Autowired
    private ISfPrebalanceRecordService sfPrebalanceRecordService;

    /**
     * 查询销售订单回款核销记录列表
     */
    @PreAuthorize("@ss.hasPermi('pay:prebalance:list')")
    @GetMapping("/list")
    public TableDataInfo list(SfPrebalanceRecord sfPrebalanceRecord)
    {
        startPage();
        List<SfPrebalanceRecord> list = sfPrebalanceRecordService.selectSfPrebalanceRecordList(sfPrebalanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出销售订单回款核销记录列表
     */
    @PreAuthorize("@ss.hasPermi('pay:prebalance:export')")
    @Log(title = "销售订单回款核销记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SfPrebalanceRecord sfPrebalanceRecord)
    {
        List<SfPrebalanceRecord> list = sfPrebalanceRecordService.selectSfPrebalanceRecordList(sfPrebalanceRecord);
        ExcelUtil<SfPrebalanceRecord> util = new ExcelUtil<SfPrebalanceRecord>(SfPrebalanceRecord.class);
        return util.exportExcel(list, "prebalance");
    }

    /**
     * 获取销售订单回款核销记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pay:prebalance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sfPrebalanceRecordService.selectSfPrebalanceRecordById(id));
    }

    /**
     * 新增销售订单回款核销记录
     */
    @PreAuthorize("@ss.hasPermi('pay:prebalance:add')")
    @Log(title = "销售订单回款核销记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SfPrebalanceRecord sfPrebalanceRecord)
    {
        return toAjax(sfPrebalanceRecordService.insertSfPrebalanceRecord(sfPrebalanceRecord));
    }

    /**
     * 修改销售订单回款核销记录
     */
    @PreAuthorize("@ss.hasPermi('pay:prebalance:edit')")
    @Log(title = "销售订单回款核销记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SfPrebalanceRecord sfPrebalanceRecord)
    {
        return toAjax(sfPrebalanceRecordService.updateSfPrebalanceRecord(sfPrebalanceRecord));
    }

    /**
     * 删除销售订单回款核销记录
     */
    @PreAuthorize("@ss.hasPermi('pay:prebalance:remove')")
    @Log(title = "销售订单回款核销记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sfPrebalanceRecordService.deleteSfPrebalanceRecordByIds(ids));
    }


    /**
     * 反核销
     */
    @RepeatSubmit
    @PostMapping(value = "/reverse")
    public AjaxResult reverse(Long id)
    {
        return sfPrebalanceRecordService.reverse(id);
    }
}
